package com.mooc.lib_network.entity

import kotlinx.coroutines.coroutineScope

/**
 * 全部网络请求基类->相当于MVVM中的Model
 * */
open class BaseRepository {

    suspend fun<T:Any> requestCall(
        call: suspend () -> NetResult<T>
    ):NetResult<T>{
        return call()
    }

    suspend fun <T : Any>handlerResponse(
        baseEntity : BaseEntity<T>
    ): NetResult<T> {
        return coroutineScope{
            if (baseEntity.status == 200){
                //请求成功
                NetResult.Success(baseEntity.data)
            }else{
                //请求失败
                NetResult.Erro("请求失败")
            }
        }
    }

}